package com.nut.controller;

import com.nut.entity.Admin;
import com.nut.entity.Message;
import com.nut.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @ author : HyoJoo-W
 * @ createDate : 2021-04-17 13:58
 * @ Description : 管理员Controller
 */

@Controller
@RequestMapping("/admin")
public class AdminController
{
    @Autowired
    private AdminService adminService;

    /**
     * @Description 管理员登录
     * @param adminName :name
     * @param adminPassword :password
     * @return 统一封装的Message
     **/
    @ResponseBody
    @RequestMapping(value = "/login/{adminName}/{adminPassword}",method = RequestMethod.GET)
    public Message login(@PathVariable("adminName")String adminName,@PathVariable("adminPassword")String adminPassword)
    {
        Admin admin = new Admin();
        admin.setName(adminName);
        admin.setPassword(adminPassword);

        Admin login = adminService.login(admin);
        if(login != null)
        {
            return Message.Success().payLoad("login_admin",login);
        }
        else
        {
            return Message.Fail().payLoad("login_admin",null);
        }
    }
}
